package com.ruoyi.crm.strategy;

import com.ruoyi.common.enums.erp.CrmFeeTypeEnum;
import com.ruoyi.common.enums.flow.FlowTypeEnum;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author YanWenliang
 * @date 2024/12/16 14:39
 * @desciption: 上下文类
 */
@Component
public class CrmOrderContext {

    @Autowired
    private Map<String, CrmOrderClearDetailsStrategy> clearDetailsMapService = new HashMap();

    @Autowired
    private Map<String, CrmOrderFlowStrategy> crmOrderFlowService = new HashMap();

    // 获取结算业务层
    public CrmOrderClearDetailsStrategy getClearDetailsService(String code){
        String name = CrmFeeTypeEnum.getName(code);

        if (StringUtils.isEmpty(name)) {
            return null;
        }
        return clearDetailsMapService.get(name);
    }

    // 获取关于审批得业务层
    public CrmOrderFlowStrategy getOrderFlowService(String info){
        String name = FlowTypeEnum.getName(info);
        if (StringUtils.isEmpty(name)) {
            throw new ServiceException("请先维护好 FlowTypeEnum 枚举类，完善该策略模式得代码");
        }

        return crmOrderFlowService.get(name);
    }


}
